using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Reflection;
using DevExpress.XtraGrid;
using DevExpress.XtraEditors;
using THSLib;

namespace THSERP.BaseProvider
{
    public partial class THSTextBox : DevExpress.XtraEditors.TextEdit
    {
        #region Variables
        protected String _THSFieldGroup;
        protected String _THSFieldRelation;
        protected THSERPScreen _screen;
        protected String _THSDataSource;
        protected String _THSDataMember;
        protected String _THSPropertyName;
        protected String _THSComment;
        protected String _THSError;
        protected String _THSPrivilege;
        #endregion

        #region Public Properties
        public THSERPScreen Screen
        {
            get { return _screen; }
            set { _screen = value; }
        }

        [Category("THS")]
        public String THSFieldGroup
        {
            get
            {
                return _THSFieldGroup;
            }
            set
            {
                _THSFieldGroup = value;
            }
        }

        [Category("THS")]
        public String THSDataSource
        {
            get
            {
                return _THSDataSource;
            }
            set
            {
                _THSDataSource = value;
            }
        }

        [Category("THS")]
        public String THSFieldRelation
        {
            get
            {
                return _THSFieldRelation;
            }
            set
            {
                _THSFieldRelation = value;
            }
        }

        [Category("THS")]
        public String THSDataMember
        {
            get
            {
                return _THSDataMember;
            }
            set
            {
                _THSDataMember = value;
            }
        }

        [Category("THS")]
        public String THSPropertyName
        {
            get
            {
                return _THSPropertyName;
            }
            set
            {
                _THSPropertyName = value;
            }
        }

        [Category("THS")]
        public String THSComment
        {
            get
            {
                return _THSComment;
            }
            set
            {
                _THSComment = value;
            }
        }

        [Category("THS")]
        public String THSError
        {
            get
            {
                return _THSError;
            }
            set
            {
                _THSError = value;
            }
        }

        [Category("THS")]
        public String THSPrivilege
        {
            get
            {
                return _THSPrivilege;
            }
            set
            {
                _THSPrivilege = value;
            }
        }
        #endregion

        #region Constructor
        public THSTextBox()
        {
            InitializeComponent();
        }

        public THSTextBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }
        #endregion

        #region--Initialize--
        public void InitializeControl()
        {
            
            if (!String.IsNullOrEmpty(this.THSDataSource) && !String.IsNullOrEmpty(this.THSDataMember))
                Screen.BindingDataControl(this);
            this.Click += new EventHandler(((BaseModuleERP)Screen.Module).Control_Click);

            this.KeyUp += new KeyEventHandler(((BaseModuleERP)Screen.Module).Control_KeyUp);

            if (THSDbUtil.IsForeignKey(this.THSDataSource, this.THSDataMember) && this.Tag.Equals(THSScreen.DataControl))
            {
                this.EditValueChanged += new EventHandler(((BaseModuleERP)Screen.Module).Control_EditValueChanged);
            }

            //Register Control Leave
            String strMainObjectTableName = THSUtil.GetTableNameFromBusinessObject(((BaseModuleERP)Screen.Module).CurrentModuleEntity.MainObject);
            String strMainObjectNameColumn = strMainObjectTableName.Substring(0, strMainObjectTableName.Length - 1) + "Name";
            //Init Default Value if Control is Top Results
            if (this.Name == THSApp.cstTopResultsSearchControl)
                this.Text = THSApp.cstTopResults.ToString();
        }
        #endregion
    }
}
